package com.cs.framework.ui.builder.json;

import org.springframework.cache.annotation.Cacheable;

import com.cs.framework.ui.model.UIInfo;
import com.cs.framework.ui.util.UIConstant;

/**
 * 通过json构建
 * 
 * @author hedongzhou
 *
 */
public class JsonUIBuilder extends AbstractJsonUIBuilder {

	/**
	 * 构建页面
	 */
	protected PageBuilder pageBuilder = new PageBuilder();

	/**
	 * 构建面板
	 */
	protected PanelBuilder panelBuilder = new PanelBuilder();

	/**
	 * 构建字段
	 */
	protected FieldBuilder fieldBuilder = new FieldBuilder();

	/**
	 * 构建UI信息
	 * 
	 * @param id
	 *            主键ID
	 * @param superId
	 *            父控件ID
	 * @return
	 */
	@Cacheable(value = "UIInfo", key = "#id + #superId")
	public UIInfo build(String id, String superId) {
		String[] arr = parseId(id);
		String prefix = arr[0];
		String viewId = arr[1];

		if (UIConstant.VIEW_PATH_FOR_PAGE.equals(prefix)) {
			return pageBuilder.build(viewId, superId);
		} else if (UIConstant.VIEW_PATH_FOR_PANEL.equals(prefix)) {
			return panelBuilder.build(viewId, superId);
		} else if (UIConstant.VIEW_PATH_FOR_FIELD.equals(prefix)) {
			return fieldBuilder.build(viewId, superId);
		}

		return null;
	}

}
